

import java.util.Date;
import java.util.Timer;

public class TestThread  extends Thread{
	
	public void run(){
		
		try {
			while(true){
				System.out.println(DateUtil.getStringDate(new Date(), "yyyy-MM-dd HH:mm:ss")+" test thread start...");
				Timer timer1 = new Timer();
				Timer timer2 = new Timer();
				Timer timer3 = new Timer();
				Timer timer4 = new Timer();
				timer1.schedule(new TestTimerTask(1), 1);
				timer1 = null;
				timer2.schedule(new TestTimerTask(2), 5*000);
				timer2 = null;
				timer3.schedule(new TestTimerTask(3), 10*60*1000);
				timer3 = null;
				timer4.schedule(new TestTimerTask(4), 20*60*1000);
				timer4 = null;
//				new Thread(new TestTimerTask(1)).start();
//				new Thread(new TestTimerTask(2)).start();
				
//				this.sleep(1000);
				throw new Exception("run方法出异常");
			}
		} catch (Exception e) {
			System.gc();
			System.err.println(DateUtil.getStringDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
			e.printStackTrace();
			System.err.println(DateUtil.getStringDate(new Date(), "yyyy-MM-dd HH:mm:ss")+"\t 主线程异常被捕获！ test thread finish...");
			System.gc();
//			System.exit(0);
		}
	}
	
	
	public static void main(String[] args) {
		try {
			TestThread  thread = new TestThread();
			thread.start();
//			System.err.println(DateUtil.getStringDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
//			Timer timer1 = new Timer();
//			timer1 = null;
//			System.gc();
//			timer1.schedule(new TestTimerTask(1), 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	
	}
	
}
